<?php
namespace app\index\controller;
use think\Controller;

class Base extends Controller{
    protected $uid;
    public function _initialize()
    {
        $this->checks();
      
    }
    
    public function checks(){
        
        $sys = D('sysconfig');
        $res = $sys->find();
        if($res['is_close']==1){
            $this->redirect("Sys/index");
        }
        $shareId = I('param.shareId');
        $params = '';
        
        $openID = session(config('httpurl'));
        if (!$openID){
            session(null);
            if ($shareId){
                $this->redirect("Auths/index",["shareId"=>$shareId]);
            }else{
                $this->redirect("Auths/index");
            }
        
        }
        $user = new \app\index\model\User();
        $userinfo = $user->getUserByOpenId($openID);
        if (!$userinfo){
            session(null);
            if ($shareId){
                $this->redirect("Auths/index",["shareId"=>$shareId]);
            }else{
                $this->redirect("Auths/index");
            }
        }
        $this->uid=$userinfo['id'];
        session("UIDS",$this->uid);
        $wx = new \app\index\model\Wx();
        $request = request();
        $url = $request->url(true);
        $this->assign('wxparam',$wx->wxSdk($url));
        $shop = new \app\index\model\Shop();
        $this->assign("shops",$shop->getShopAll());
        $this->assign("moneys",$userinfo['money']);
        $this->assign("uid",$userinfo['id']);
        $this->assign("apihost",config("apihost"));
        $this->assign("select_tab","");
    }
    
 public function __construct(){
      parent::__construct(); //调用父类的构造方法
  }
  
  
  public  function param_error()
    {         
        $_arr['flag'] = -1;
        $_arr['msg'] = '参数错误';
        $_arr['data'] = '';
        return json($_arr);
    }
    
    protected function returnError($errorMsg='',$data='')
    {
        $_arr['flag'] = -1;
        $_arr['msg'] = $errorMsg;
        $_arr['data'] = $data;
        return json($_arr);
    }
    
    protected function returnAlert($alertMsg='',$data='')
    {
        $_arr['flag'] = 1;
        $_arr['msg'] = $alertMsg;
        $_arr['data'] = $data;
        return json($_arr);
    }
    
    protected function returnOk($data='',$msg='')
    {
        $_arr['flag'] = 0;
        $_arr['msg'] = $msg;
        $_arr['data'] = $data;
        return json($_arr);
    }

    public function _empty()
    { 
        $this->redirect("Error/index");
    }


}